package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class ScheduledTask {
    @Autowired
    private RabbitService rabbitService;

    //@Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点执行定时
    @Scheduled(cron = "0/20 * * * * ?") //每隔20秒执行定时任务
    public void sendMsg(){

        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"随便发个消息即可");
        System.out.println("任务消息：通知service-activity 进行加载秒杀商品到redis");
    }
}
